package com.szyportal.web.front.controller;

import com.szyportal.common.core.controller.BaseController;
import com.szyportal.custom.domain.WConfig;
import com.szyportal.custom.domain.WServices;
import com.szyportal.custom.service.IWConfigService;
import com.szyportal.custom.service.IWServicesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
public class ServiceController extends BaseController {

    @Autowired
    private IWServicesService wServicesService;
    @Autowired
    private IWConfigService wConfigService;

    @GetMapping("/service.html")
    public String service(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
        List<WServices> wServices = wServicesService.selectWServicesList(null);
        model.addAttribute("wServices",wServices);
        WConfig wConfig = wConfigService.selectWConfigById(1l);
        model.put("wConfig",wConfig);
        return "front/service";
    }

    // 查看详情
    @GetMapping("/service/details")
    public String details(HttpServletRequest request, @RequestParam("serviceId") String serviceId, HttpServletResponse response, ModelMap model) {
        WServices wServices = wServicesService.selectWServicesById(Long.parseLong(serviceId));
        WServices prewService = wServicesService.selectWServicesById(wServices.getPrewId());
        WServices nextService = wServicesService.selectWServicesById(wServices.getNextId());
        WConfig wConfig = wConfigService.selectWConfigById(1l);
        model.put("wConfig",wConfig);
        model.put("service", wServices);
        model.put("prewService", prewService);
        model.put("nextService", nextService);
        return "front/service_details";
    }
}
